#include <cstdlib>
#include <cstdio>
#include <cstring>

#include "header.h"
#include "display.h"
#include "sampling.h"
#include "compare.h"
#include "des_gen.h"
#include "evaluate.h"
#include "voxelization.h"

int main (int argc, char** argv) {
	const int BW = 8;
	char cmd;
	char* arg2=new char[80];

	if(argc==1) {
		cout<<"Please choose a task (Press '0' to exit):"<<endl;
		cout<<" [A]dd an obj file to database"<<endl;
		cout<<" [S]earch by keyword or obj file"<<endl;
		cout<<" [E]valuate the search result"<<endl;
		cin>>cmd;
		if (isupper(cmd))
			cmd=tolower(cmd);
	} else {
		cmd=argv[1][1];
	}

	switch (cmd) {
	case 'a': {	
		if (argc<3) {
			cout<<"Please enter the name of the obj:"<<endl;
			cin>>arg2;
		} else {
			strcpy(arg2, argv[2]);
		}

		//Sampling* sp = new RayTracer;
		Sampling* sp;
		Descriptor* dp;
		if (!strcmp(argv[3], "-v"))
			sp = new voxelization;
		else
			sp = new RayTracer;
	
		dp = new SphHarmo;
		
		sp->objloader(arg2,1);
		sp->getsample(arg2,BW);
		dp->getdes(arg2,BW);
		}
		break;

	/*  calculate the L2 distance based on SHDs  */
	case 's': {
		if (argc<3) {
			cout<<"Please enter the name of the query key:"<<endl;
			cin>>arg2;
		} else {
			strcpy(arg2, argv[2]);
		}

		Compare* l2d=new L2dist();

		l2d->setdes();
		l2d->rank(arg2);
		}
		break;

	/* display the sampled object */
	case 'r': {
		readingfile(BW,argv[2]);
		}
		break;
	
	case 'e': {
		if (argc<3) {
			cout<<"Please enter the number of returned result:"<<endl;
			cin>>arg2;
		} else {
			strcpy(arg2, argv[2]);
		}

		Evaluate ev;

		ev.makelist(1);
		ev.prcurve(atoi(arg2));
		}
		break;

	default:
		cout<<"exit"<<endl;
		break;
	}
	
	return 0;
}
